# -*- coding: utf-8 -*-
"""
author:码同学 极光
date:2023-01-16
desc: 
sample: 
"""
import csv
import os

import pandas as pd

print(os.path.dirname(__file__))


def get_project_path():
    return os.path.dirname(__file__)


def getcsv_list(path, hasHeader=True):
    list = []
    with open(path, encoding="utf-8") as f:
        csv_reader = csv.reader(f)
        if hasHeader:
            next(csv_reader)
        for line in csv_reader:
          list.append(line)
    return list


def getcsv_listdict(path,hasHeader=True):
    list = []
    if hasHeader:
     with open(path, encoding="utf-8") as f:
        csv_reader = csv.DictReader(f)
        for line in csv_reader:
            list.append(line)
    return list

def getExcelListBypandas(path, sheet=0):
    excel= pd.read_excel(path,sheet)
    return excel.values.tolist()

#print(getExcelListBypandas(path,1))

def getExcelListDictBypandas(path, sheet=0):
    excel= pd.read_excel(path,sheet)
    head_list = list(excel.columns)  # 拿到表头列表
    excel_list=[]
    for valuelist in excel.values:
        excel_list.append(dict(zip(head_list,valuelist)))
    return excel_list

if __name__ == '__main__':
    path = os.path.join(get_project_path(), "files", "sku.csv")
    print(getcsv_list(path, False)) #list（list）可以没有头部
    print(getcsv_list(path))
    print(getcsv_listdict(path))